﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLNHDAO;

namespace QLNHBUS
{
    public class MonAnBUS
    {
        public static List<MonAn>LayDanhSachMonAn(int id)
        {
            MonAnDAO ban = new MonAnDAO();
            return ban.SearchFor(c => c.NhomMonAn.MaNhomMonAn == id).ToList();
        }

        public static List<object> LayDanhSachMonAnChuaXoa(int id)
        {
            MonAnDAO maDAO = new MonAnDAO();
            var result = maDAO.SearchFor(c => (c.NhomMonAn.MaNhomMonAn == id && c.Xoa == false)).ToList();

            var filter = from ma in result
                         select new { ma.MaMonAn, ma.Ten, ma.GhiChu, NhomMonAn = ma.NhomMonAn.Ten, TenDonVi = ma.DonVi.Ten, ma.GiaHienHanh };
            return filter.ToList<object>();
        }

        public static void XoaMonAn(int mamonan)
        {
            MonAnDAO maDAO = new MonAnDAO();
            MonAn monan = maDAO.GetByID(mamonan);
            monan.Xoa = true;
            maDAO.Update(monan);
        }

        public static MonAn LayMonAn(int mamonan)
        {
            MonAnDAO maDAO = new MonAnDAO();
            MonAn monan = maDAO.GetByID(mamonan);
            return monan;
        }

        public static void ThemMonAn(MonAn monan)
        {
            MonAnDAO maDAO = new MonAnDAO();
            maDAO.Add(monan);
        }

        public static void CapNhatMonAn(MonAn monan)
        {
            MonAnDAO maDAO = new MonAnDAO();
            maDAO.Update(monan);
        }
    }
}
